<template>
  <div class="box" v-if='datalist'>
    <div class="search">
      <div class="left">
        <i class="iconfont icon-search"></i>
        <input type="text" placeholder="输入影院名字" v-model="mytext"/>
      </div>

      <div class="cancel" @click='goback'>取消</div>
      <cinemaslist :datalist='topDataList'></cinemaslist>
    </div>
    <div class="nextlist" v-show='mytext==""'>
      <div class="next">离你最近</div>
      <ul>
        <li v-for="data in datalist" :key="data.cinemaId">{{data.name}}</li>
      </ul>
    </div>
    <div v-show='empty' class="cinema-search-result" style=""><div class="empty-result" data-enter-time="1582939722" data-leave-time="1582939721"><img src="" alt=""> <p>没有找到匹配的影院</p> <p class="empty-list-tip">提示：仅支持搜索“影院”，建议您检查输入的影院名称是否有误？ </p></div></div>
  </div>
</template>
<style lang="scss" scoped>
</style>

<script>
import cinemaslist from '../components/Cinemalist'
import { mapState, mapGetters, mapActions } from 'vuex'
export default {
  components: {
    cinemaslist
  },
  data () {
    return {
      datalist: [],
      mytext: '',
      empty:false

    }
  },
  mounted () {
    if (this.cinemaList.length === 0) {
      this.findCinemaList(this.cityId)
    }
    this.$store.commit('tabber/hide')
    this.axios({
      url: `https://m.maizuo.com/gateway?cityId=${this.cityId}&k=1796289`,
      method: 'get',
      headers: {
        'X-Host': 'mall.film-ticket.cinema.recommend',
        'X-Requested-With': 'XMLHttpRequest'
      }
    }).then(res => {
      this.datalist = res.data.data.cinemas
    })
  },
  destroyed () {
    setTimeout(() => {
      this.$store.commit('tabber/show')
    }, 1000)
  },
  computed: {
    ...mapState('cinema', ['cinemaList']),
    ...mapState('cityN', ['cityId']),
    // eslint-disable-next-line vue/return-in-computed-property
    topDataList () {
      if (this.cinemaList) {
        if (this.mytext) {
          const arr = this.cinemaList.filter(val => val.name.includes(this.mytext))
          if (arr.length === 0) {
            // eslint-disable-next-line vue/no-side-effects-in-computed-properties
            this.empty = true
            console.log(22222)
          } else {
            // eslint-disable-next-line vue/no-side-effects-in-computed-properties
            this.empty = false
            console.log(11111)
            return arr
          }
        } else {
          // eslint-disable-next-line vue/no-side-effects-in-computed-properties
          this.empty = false
        }
      }
    }
  },
  methods: {
    ...mapActions('cinema', ['findCinemaList']),
    goback () {
      this.$router.push('/cinemas')
    }
  }
}
</script>
<style lang="scss" scoped>
* {
  margin: 0;
  padding: 0;
}
.box{width: 100%;height: 100%;background-color: #fff;position: fixed;left: 0;top: 0;}
.search {
  overflow: hidden;
  min-height: 49px;
  padding: 9.5px 15px;
  background-color: #fff;
  .left {
    float: left;
    width: calc(100% - 43px);
    background-color: #f4f4f4;
    display: inline-block;
    border-radius: 3px;
    height: 30px;
    i{margin:0 10px;vertical-align: middle;}
    input{font-size:14px}
  }
  input {
    left: 33.5px;
    top: 0;
    height: 30px;
    width: calc(100% - 65px);
    border: 0;
    background: #f4f4f4;
  }
  .cancel {
    width: 43px;
    display: inline-block;
    text-align: right;
    font-size: 14px;
    line-height: 30px;
    float: right;
  }
}
.nextlist {
  background-color: #fff;
  padding: 18px 15px 0 15px;
}
.next {
  font-size: 13px;
  line-height: 13px;
  color: #bdc0c5;
  margin-bottom: 18px;
}
ul {
  display: flex;
  justify-content: flex-start;
  align-content: center;
  flex-wrap: wrap;
  li {
    text-align: center;
    margin: 0 10px 10px 0;
    padding-bottom: 10px;
    padding-right: 10px;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    float: left;
    list-style: none;
    height: 30px;
    background-color: rgba(233, 231, 231, 0.3);
    line-height: 14px;
    border-radius: 3px;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    font-size: 13px;
    padding: 8px 12px;
  }
}
.cinema-search-result {
    z-index: 3004;
    position: absolute;
    top: 49px;
    bottom: 0;
    left: 0;
    background-color: #fff;
    height: calc(100vh - 49px);
    width: 100vw;
    overflow-y: auto;
}
.cinema-search-result .empty-result {
    position: absolute;
    top: 107px;
    width: 100%;
    text-align: center;
}
.cinema-search-result .empty-result img {
    width: 90px;
    margin: auto;
}
.cinema-search-result .empty-result p {
    color: #bdc0c5;
    font-size: 14px;
    margin: 0;
}
.cinema-search-result .empty-result .empty-list-tip {
    font-size: 11px;
    padding: 0 22vw;
}
.cinema-search-result .empty-result p {
    color: #bdc0c5;
    font-size: 14px;
    margin: 0;
}
</style>
